package com.intelligent.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.intelligent.mapper.PurchaseOrderMapper;
import com.intelligent.pojo.PurchaseOrder;
import com.intelligent.service.SupplierReconciliationDetailService;
import com.intelligent.utils.Result;
import com.intelligent.vo.SupplierReconciliationDetailPageReq;
import com.intelligent.vo.SupplierReconciliationDetailResp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/supplier/detail")
public class SupplierReconciliationDetailController {

    @Autowired
    private SupplierReconciliationDetailService supplierReconciliationDetailService;


    //分页查询供应商对账明细
    @PostMapping("/page")
    public Result<Page<SupplierReconciliationDetailResp>> page(@RequestBody SupplierReconciliationDetailPageReq req) {
        Page<SupplierReconciliationDetailResp> page = supplierReconciliationDetailService.pageDetails(req);
        return Result.success(page);
    }

    //根据ID获取对账明细详情
    @GetMapping("/{id}")
    public Result<SupplierReconciliationDetailResp> detail(@PathVariable Long id) {
        SupplierReconciliationDetailResp detail = supplierReconciliationDetailService.getDetail(id);
        return Result.success(detail);
    }

    //根据供应商对账单生成对应的供应商对账明细
    @PostMapping("/generate/{reconciliationId}")
    public Result<String> generateFromReconciliation(@PathVariable Long reconciliationId) {
        try {
            supplierReconciliationDetailService.generateFromReconciliation(reconciliationId);
            return Result.success("生成成功");
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }




}
